x86/domctl: Fix TOCTOU race with the use of XEN_DOMCTL_getvcpuextstate
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 12 Sep 2016 09:30:00 +0000 (10:30 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 13 Sep 2016 09:43:59 +0000 (10:43 +0100)
commitd4a322557ae98cccdf90a0f442a29e1f5d76378a
treea663f28c6f8e8886f3a6c49eae5c7062a0af1af5
parent80b9ea63b0955c692a71bc841f4ec0a501da7c4b
x86/domctl: Fix TOCTOU race with the use of XEN_DOMCTL_getvcpuextstate

A toolstack must call XEN_DOMCTL_getvcpuextstate twice; first to find the size
of the buffer to use, and a second time to get the actual content.

The reported size was based on v->arch.xcr0_accum, but a guest which extends
its xcr0_accum between the two hypercalls will cause the toolstack to fail the
evc->size != size check, as the provided buffer is now too small.  This causes
a hard error during the final phase of migration.

Instead, return a size based on xfeature_mask, which is the maximum size Xen
will ever permit.  The hypercall must now tolerate a toolstack-provided buffer
which is overly large (for the case where a guest isn't using all available
xsave states), and should write back how much data was actually written into
the buffer.

As the query for size now has no dependence on vcpu state, the vcpu_pause()
can be omitted for a small performance improvement.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/domctl.c